<div class="row-fluid">
	<div class="span12">
		<ul class="breadcrumb">
			<li>
				<a href="index.php">
					<i class="radmin-icon radmin-home"></i>
					<?php echo t('page', 'Dashboard'); ?>
				</a>
				<span class="divider">/</span>
			</li>
			<li class="active">
				<a href="user-list.php">
					<i class="radmin-icon radmin-user"></i>
					<?php echo t('page', 'User List'); ?>
				</a>
				<span class="divider">/</span>
			</li>
			<li class="active">
				<i class="radmin-icon radmin-user-2"></i>
				<?php echo t('page', 'Edit User Profile'); ?>
			</li>
		</ul>
	</div>
</div>

<div class="row-fluid">
	<div class="span12">
		<h4 class="title"><?php $this->widget('application.components.mywidgets.WikiHelp', array('wiki' => 'user_edit')); ?> <?php echo t('page', 'Edit User Profile'); ?> | John Doe</h4>
		<div class="squiggly-border"></div>
		
		<?php echo CHtml::dropDownList('id_users', $users[0]->id_user, CHtml::listData($users, 'id_user', 'fullname'), array('empty' => count($users) . ' User to Edit')); ?>
		<script>
			function getIndividualInfo(id_user)
			{
				$('.fields').each(function(k, v){
					$(v).data('OLD_placeholder', $(v).attr('placeholder') == undefined? '' : $(v).attr('placeholder'));
					$(v).attr('placeholder', 'Loading...');
					$(v).attr('disabled', true);
					$(v).val('');
				});
				
				$.ajax({
					type: 'get',
					url: <?php echo json_encode(url('user/getindividualinfo')); ?>,
					data: {
						id_user: id_user
					},
					success: function(ret){
						$('.fields').each(function(k, v){
							$(v).attr('placeholder', $(v).data('OLD_placeholder'));
							$(v).removeAttr('disabled');
						});
						$('.fields').val('');
						
						if(ret){
							$('#UserEditForm_id_user, #UserOptionForm_id_user').val(id_user);
							
							$('#UserEditForm_firstname').val(ret.profile.firstname);
							$('#UserEditForm_lastname').val(ret.profile.lastname);
							$('#UserEditForm_email').val(ret.profile.email);
							$('#UserEditForm_username').val(ret.profile.username);
							$('#UserEditForm_id_user_role').val(ret.profile.id_user_role);

							$('#UserOptionForm_wiki_help').val(ret.option.wiki_help);
							$('#UserOptionForm_language').val(ret.option.language);
							$('#UserOptionForm_pagination').val(ret.option.pagination);
							ret.option.allow_reset_restrict_ip_byemail == 1? $('#UserOptionForm_allow_reset_restrict_ip_byemail').attr('checked', true) : $('#UserOptionForm_allow_reset_restrict_ip_byemail').removeAttr('checked');
							$('#UserOptionForm_restrict_ips').val(ret.option.restrict_ips);
						}
					},
					dataType: 'json'
				});
			}
		
			$('select#id_users').change(function(){
				var id_user = $(this).val();
				if(id_user == ''){
					$('.fields').val('');
				}else{
					getIndividualInfo(id_user);
				}
			});
			$(document).ready(function(){
				$('select#id_users').change();
			});
		</script>
		
		<?php $this->renderPartial('forms/user/_individual_profile', array('user' => $users[0], 'userEditForm' => $userEditForm)); ?> 
		<?php $this->renderPartial('forms/user/_individual_option', array('user' => $users[0], 'userOptionForm' => $userOptionForm)); ?>
		<?php $this->renderPartial('forms/user/_individual_authy', array('user' => $users[0])); ?>
	</div>
</div>